const authMiddleware = require('../middleware/auth')
module.exports = (app) => {
    const path = require('path')
        // 上传图片
    const multer = require('multer');
    // 使用阿里云 OSS 存储图片
    const MAO = require('multer-aliyun-oss');
    let upload = multer({
        // dest: path.join(__dirname, '../upload')
        // 需要阿里云配置 OSS
        storage: MAO({
            config: {
                region: 'oss-cn-hongkong',
                accessKeyId: 'LTAI4GGndU3wk74XqLMD3gBD',
                accessKeySecret: '1JOdr2x4guPvCfF0p15fSAHLvNe9NH',
                bucket: 'node-pvp'
            }
        })

    })
    app.post('/admin/api/upload', authMiddleware(), upload.single('file'), async(req, res) => {

        // const url = `${req.host}/upload/${req.file.filename}${path.extname(req.file.originalname)}`
        // console.log(req.file)

        // const url = `http://${req.host}/upload/${req.file.filename}`
        // req.file.url = url
        res.send(req.file)
    })
}